﻿using Honeycomb.Transport;
using System;

namespace Honeycomb.Protocol
{
    /// <summary>
    /// Protocol server is responsible for setting up listening port and delegating client connections.
    /// </summary>
    public sealed class ProtocolServer : IDisposable
    {
        /// <summary>
        /// INetworkServer implementation.
        /// </summary>
        private readonly INetworkServer networkServer;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="networkServer"></param>
        public ProtocolServer(INetworkServer networkServer)
        {
            this.networkServer = networkServer;
        }

        /// <summary>
        /// Accept an incoming connection.
        /// </summary>
        /// <returns>ProtocolPeer instance.</returns>
        public ProtocolPeer AcceptConnection()
        {
            return new ProtocolPeer(networkServer.AcceptConnection()); 
        }

        /// <summary>
        /// Dispose.
        /// </summary>
        public void Dispose()
        {
            networkServer.Dispose();
        }
    }
}